#!/bin/sh

# restoreccdata - Restore critical console data from an archive file
#
# Usage: restoreccdata <archive> <logfile>
# This script must be run by a user with appropriate privileges (e.g., root)
#
# archive: the filename of the restore archive
# logfile: the filename of the log file to create
#
# Return Codes:
# 1 - tar error

CURRENTDIR=$PWD
ARCHIVE=$1
LOG=$2

# Start log
echo -e "-> restoreccdata `date`\n" >> $LOG

# make sure we are in the root directory
cd /

if !(tar -xvjPf $ARCHIVE --overwrite --exclude actbrst.trm > /tmp/tareslog 2>&1); then
    echo -e "tar error extracting files from archive.. exiting\n" >> /tmp/tareslog
	cd $CURRENTDIR
    exit 1
fi

# return to the directory we started from, otherwise we could mess up the HMC
cd $CURRENTDIR

cat /tmp/tareslog >> $LOG

# stop log
echo -e "<- restoreccdata\n" >> $LOG

exit 0
